const path = require('path')
const config = require('./package.json')
function resolve(dir = '') {
  return path.join(__dirname, './src', dir)
}
// console.log(config)
module.exports = {
  // webpack-dev-server 相关配置
  devServer: {
    open: false,
    host: '0.0.0.0',
    port: 8889,
    https: false,
    hotOnly: false,
    disableHostCheck: true,
    // 设置代理
    proxy: {
      '/api': {
        target: 'http://baidu.com',
        changeOrigin: true,
        secure: false,
        pathRewrite: {
          '^/api': '/api',
        },
      },
    },
  },
  publicPath: process.env.NODE_ENV === 'production' ? '/' : '/',
  // 生产环境关eslint
  lintOnSave: process.env.NODE_ENV !== 'production',
  chainWebpack: (config) => {
    // 打包后，html使用双引号（默认去掉双引号）
    if (process.env.NODE_ENV === 'production') {
      config.plugin('html').init((Plugin, args) => {
        const newArgs = {
          ...args[0],
        }
        newArgs.minify.removeAttributeQuotes = false
        return new Plugin(newArgs)
      })
    }
  },
  configureWebpack: {
    plugins: [],
    resolve: {},
  },
  // sass-loader配置
  css: {
    loaderOptions: {
      sass: {
        prependData: '@import "@/scss/settings.scss";',
      },
    },
    // 生产环境开启sourceMap
    sourceMap: process.env.NODE_ENV === 'production',
  },
}
